Function Add-ADgroup
{
	#Variable that contains the contents of the group list
	$d = Get-Content "D:\Powershell\AddingADGroup.txt"
	#Name of local group to add user or group from  
	$localGroupName = 'Administrators'
	#Variable that contains the contents of the servername list  
	$c = Get-Content "D:\Powershell\Computers.txt"
	If (($d -ne $Null) -and ($c -ne $null)) {
	#read each name and execute below script against each name in the list  
		foreach ($comp in $c)
		{
		#Variable reassignment  
		$computerName = $comp
		#read each name and execute below script against each name in the list  
		foreach ($user in $d)
			{
			#Variable reassignment  
			$userName = $user
			#This reads the local domain and prepends it to the USERID  
			[string]$domainName = ([ADSI]'').name
			# We are providing a yes so that we are not prompted for each computer  
			$confirm = "Y"
			if ($confirm -eq "Y") {
				try
				{
					write-host "Adding $userName to $localGroupName group on $computerName"
					([ADSI]"WinNT://$computerName/$localGroupName,group").add("WinNT://$domainName/$userName")
					Write-Host "User $domainName\$userName has been added from local group $localGroupName on computer $computerName." -foregroundcolor Green
				}
				Catch [System.Management.Automation.MethodInvocationException]
				{
					write-host "Caught an exception:" -ForegroundColor Red
					if ($($_.Exception.Message) -Like "*already a member*") 
					{
						write-host "'$domainName\$userName' is already a member of $localGroupName group on computer $computerName" -ForegroundColor Magenta
					} elseif($($_.Exception.Message) -Like "*does not exist*") 
					{
					write-host "'$domainName\$userName' could not be added to $localGroupName group because this group does not exist." -ForegroundColor Red
					} else 
					{
					write-host "Access Denied for current user to execute against computer $computerName" -ForegroundColor cyan
					}
				}
		}
		}
		}
	} else {
	write-host "Pre-requisite is not in place" -ForegroundColor Red
	}
}